


set(protofiles "compile.proto")
set(cur_path ${CMAKE_CURRENT_BINARY_DIR})
set(src_path ${CMAKE_CURRENT_LIST_DIR})
set(proto_path ${CMAKE_SOURCE_DIR}/src/protos)
set(compile_output_path ${CMAKE_SOURCE_DIR}/build/src)


# 生成protobuf文件
set(src_list "")
foreach(file  ${protofiles})
# compile protobuf file 
    set(hfile "")
    set(sfile "")
    string(REPLACE ".proto" ".pb.h" hfile ${file}) # problem.pb.h
    string(REPLACE ".proto" ".pb.cc" sfile ${file}) # problem.pb.cc
    if(NOT EXISTS ${compile_output_path}/${sfile}) 
        execute_process( # 这个指令是在cmake .. 执行的时候，就执行
            COMMAND protoc
                    -I ${proto_path} 
                    --cpp_out=${compile_output_path} 
                    ${proto_path}/${file}
        )
    endif()
    list(APPEND src_list ${compile_output_path}/${sfile})
endforeach()

# file(GLOB SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/compile-server.cc)
# file(GLOB SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/test.cpp)

set(src compile-server.cc)
# set(test_src test.cpp)

add_executable(compileserver ${src} ${src_list} )
# add_executable(test ${test_src} ${src_list} )
target_include_directories(compileserver PUBLIC ${compile_output_path})
# target_include_directories(test PUBLIC ${compile_output_path})

target_link_libraries(compileserver PUBLIC 
    brpc_etcd # etcd brpc
     # es
)
# target_link_libraries(test PUBLIC 
#     brpc_etcd # etcd brpc
#      # es
# )

# 拷贝runner-daemon 到可执行程序目录下
execute_process( # 这个指令是在cmake .. 执行的时候，就执行
            COMMAND cp
                    ${src_path}/runner-daemon
                    ${cur_path}/Dockerfile
        )